﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Portal.Xml.Utility;

namespace Portal.Exam.Model
{
    public class GroupQuestionCls
    {
        public string GroupQuestionId;
        public string GroupQuestionName;
        public string Description;
        public string ParentGroupQuestionId;
        public int SortIndex;
    }

    public class GroupQuestionParser
    {
        public static GroupQuestionCls CreateInstance()
        {
            //tao 1 class trang....
            GroupQuestionCls oGroupQuestionCls = new GroupQuestionCls();
            return oGroupQuestionCls;
        }

        public static GroupQuestionCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            GroupQuestionCls oGroupQuestionCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oGroupQuestionCls;
        }


        public static GroupQuestionCls ParseFromDataRow(DataRow dr)
        {
            GroupQuestionCls oGroupQuestionCls = new GroupQuestionCls();
            oGroupQuestionCls.GroupQuestionId = XmlUtility.GetString(dr, "GroupQuestionId", true);
            oGroupQuestionCls.GroupQuestionName = XmlUtility.GetString(dr, "GroupQuestionName", true);
            oGroupQuestionCls.Description = XmlUtility.GetString(dr, "Description", true);
            oGroupQuestionCls.Description = XmlUtility.GetString(dr, "Description", true);
            oGroupQuestionCls.ParentGroupQuestionId = XmlUtility.GetString(dr, "frkParentGroupQuestionId", true);
            oGroupQuestionCls.SortIndex = XmlUtility.GetInt(dr, "SortIndex", true);

            return oGroupQuestionCls;
        }

        public static GroupQuestionCls[] ParseFromDataTable(DataTable dtTable)
        {
            GroupQuestionCls[] GroupQuestions = new GroupQuestionCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                GroupQuestions[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return GroupQuestions;
        }

        public static GroupQuestionCls[] ParseMultiRecordFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            if (ds.Tables.Count == 0)
            {
                return new GroupQuestionCls[0];
            }
            GroupQuestionCls[] GroupQuestions = new GroupQuestionCls[ds.Tables[0].Rows.Count];
            for (int iIndex = 0; iIndex < ds.Tables[0].Rows.Count; iIndex++)
            {
                GroupQuestions[iIndex] = ParseFromDataRow(ds.Tables[0].Rows[iIndex]);
            }
            return GroupQuestions;
        }
    }
}

